package com.allwees.data.analysis.stat.vo;

import com.allwees.bs.core.model.stat.EStatType;
import com.allwees.bs.core.modelbase.constant.EPlatform;
import com.allwees.bs.core.modelbase.vo.Vo;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 *
 *
 * @author yangylsky
 * @since 2020-04-14
 *
 */
@Data
@EqualsAndHashCode(callSuper=false)
@Accessors(chain = true)
public abstract class StatInfo extends Vo {
    protected EStatType statType;

    protected String statTypeDesc;

    protected EPlatform platform;

    protected String bsKey;

    protected String name;

    protected BigDecimal value = BigDecimal.ZERO;

    @SuppressWarnings("unchecked")
	public <S extends StatInfo> S setStatType(EStatType statType) {
    	this.statType = statType;
    	this.statTypeDesc = statType.getDesc();
    	return (S) this;
    }

    @SuppressWarnings("unchecked")
	public <S extends StatInfo> S setValue(BigDecimal value) {
    	if(value != null) {
        	this.value = value.setScale(4, RoundingMode.HALF_UP);
    	}
    	return (S) this;
    }

    public <S extends StatInfo> S setValue(Double value) {
    	return setValue(BigDecimal.valueOf(value));
    }
}
